package com.mcp.converter.domain.rule.compatibility.datatype;

import com.mcp.converter.domain.checker.IncompatibilityDetail;
import com.mcp.converter.shared.response.sql.SQLElement;
import com.mcp.converter.domain.rule.compatibility.AbstractDataTypeRule;

/**
 * LONG数据类型兼容性规则
 * OceanBase不支持LONG数据类型
 *
 * @author zengxiong
 */
public class LongDataTypeRule extends AbstractDataTypeRule {

    private static final String RULE_ID = "DT002";
    private static final String RULE_NAME = "LONG数据类型不兼容";
    private static final String RULE_DESCRIPTION = "OceanBase不支持LONG数据类型，建议使用CLOB替代";

    public LongDataTypeRule() {
        super(RULE_ID, RULE_NAME, RULE_DESCRIPTION);
        setIncompatibilityDetail("OceanBase不支持LONG数据类型，该类型在Oracle中已被废弃", "使用LONG数据类型的SQL语句在OceanBase中将执行失败",
                "建议使用CLOB数据类型替代LONG数据类型", IncompatibilityDetail.Severity.CRITICAL);
    }

    @Override
    public boolean matches(Object target) {
        if (target instanceof SQLElement) {
            SQLElement element = (SQLElement) target;
            if (isDataTypeElement(element)) {
                String dataTypeName = element.getName().toUpperCase();
                return "LONG".equals(dataTypeName) && !"LONG RAW".equals(dataTypeName);
            }
        }
        return false;
    }
}
